package com.net;

import android.util.Log;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by xiaolong.wei on 2018/8/13.
 */

public abstract class HKResponseResultCallBack<T> implements Callback {

    private static final String TAG = "HKResponseResultCallBack";


//    HKResponseCallback<T> hkResponseCallback;
//    public HKResponseResultCallBack(HKResponseCallback<T> hkResponseCallback){
//        this.hkResponseCallback = hkResponseCallback;
//    }

    @Override
    public void onResponse(Call call, Response response) {
        Log.d(TAG, "onResponse: ");
        BaseResponse<T> body = (BaseResponse<T>) response.body();

        if (body.getCd() == 0){
            onSuccess(body.getData());
        }else{
            onGetDataFailed(body.getCd(),body.getMsg());
        }
    }

    @Override
    public void onFailure(Call call, Throwable t) {
        onFailed(call,t);
    }

    public abstract  void onSuccess(T t);
    public abstract void onGetDataFailed(int cd , String msg);
    public abstract void onFailed(Call call,Throwable t);

}
